function selectexpress(page,state){
	$.ajax({
		url:'/express/findexpress',
		type:'get',
		data:{'state':state,'page':page},
		dataType:'json',
		success:function(res){
			$("#request").empty();
			for (var i = 0; i < res.length; i++) {
				var content='';
				content='<tr class="gradeX">'
                    +'<td>'+res[i].sendtime+'</td>'
                    +'<td>'+res[i].expresswo+'</td>'
                    +'<td>'+res[i].expressname+'</td>'
                    +'<td>'+res[i].sendname+'</td>'
                    +'<td>'+res[i].sendphone+'</td>'
                    +'<td>'+res[i].sendaddress+'</td>'
                    +'<td>'+res[i].receivename+'</td>'
                    +'<td>'+res[i].receivephone+'</td>'
                    +'<td>'+res[i].receiveaddress+'</td>'
                    +'<td>'+res[i].way+'</td>'
                    +' <td>'
                    +'<div class="tpl-table-black-operation">'
                    +'<a onclick="lookexpress($(this))" class="am-btn am-btn-primary" style="color:#ffffff">'
                    +'<i class="am-icon-check"></i>查看物流'
                    +'</a>'
                    +'<a href="javascript:receive('+res[i].id+',1);" class="am-btn am-btn-success" style="color:#ffffff">'
                    +'<i class="am-icon-check"></i>收到'
                    +'</a>'
                    +'</div>'
                    +' </td>'
                    +'</tr>';
				$("#request").append($(content));
			}
		},
		error:function(){
			layer.msg('连接失败')
		}
	})
}
function counts(state){
	$.ajax({
		url:'/express/counts',
		type:'get',
		data:{'state':state},
		dateType:'json',
		success:function(res){
			page=Math.ceil(res/10);
		},
		error:function(){
			layer.msg('连接失败')
		}
	})
}

function receive(id,state){
	$.ajax({
		url:'/express/state',
		type:'post',
		data:{'id':id,'state':state},
		dataType:'json',
		success:function(res){
			if(res.success){
				 window.location.reload();
			}
			layer.msg(res.msg)
		},
		error:function(){
			layer.msg('连接失败')
		}
	})
}
function search(){
	var expresswo = $("#search").val();
	$.ajax({
		url:'/express/search',
		type:'get',
		data:{'expresswo':expresswo},
		dataType:'json',
		success:function(res){
			$("#request").empty();
			var content='';
			content='<tr class="gradeX">'
                +'<td>'+res.sendtime+'</td>'
                +'<td>'+res.expresswo+'</td>'
                +'<td>'+res.expressname+'</td>'
                +'<td>'+res.sendname+'</td>'
                +'<td>'+res.sendphone+'</td>'
                +'<td>'+res.sendaddress+'</td>'
                +'<td>'+res.receivename+'</td>'
                +'<td>'+res.receivephone+'</td>'
                +'<td>'+res.receiveaddress+'</td>'
                +'<td>'+res.way+'</td>'
                +' <td>'
                +'<div class="tpl-table-black-operation">'
                +'<a onclick="lookexpress($(this))" class="am-btn am-btn-primary" style="color:#ffffff">'
                +'<i class="am-icon-check"></i>查看物流'
                +'</a>'
                +'<a href="javascript:receive('+res.id+',1);" class="am-btn am-btn-success" style="color:#ffffff">'
                +'<i class="am-icon-check"></i>收到'
                +'</a>'
                +'</div>'
                +' </td>'
                +'</tr>';
			$("#request").append($(content));
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}
function lookexpress(obj){
	var expresswo = obj.parent().parent().parent().find("td:eq(1)").html();
	$.ajax({
		url:'http://www.tuling123.com/openapi/api?key=8a20b49d802743b4a2932f43acf8434c&info=%E6%9F%A5%E5%BF%AB%E9%80%92&userid=123456',
		type:'get',
		data:'json',
		success:function(res){
			$.ajax({
				url:'http://www.tuling123.com/openapi/api',
				type:'get',
				data:{'key':'8a20b49d802743b4a2932f43acf8434c','info':expresswo,'userid':'123456'},
				dataType:'json',
				success:function(res){
					var text = res.text.replace(/\n/g,"</br>")
					layer.open({
						  type: 1,
						  title:'物流跟踪',
						  skin: 'layui-layer-rim', //加上边框
						  area: ['420px', '500px'], //宽高
						  content: text
						});
				},
				error:function(){
					layer.msg("连接失败")
				}
			})
		},
		error:function(){
			layer.msg("请求失败")
		}
	})
}
function selectexpressfinish(page,state){
	$.ajax({
		url:'/express/findexpress',
		type:'get',
		data:{'state':state,'page':page},
		dataType:'json',
		success:function(res){
			$("#request").empty();
			for (var i = 0; i < res.length; i++) {
				var content='';
				content='<tr class="gradeX">'
                    +'<td>'+res[i].sendtime+'</td>'
                    +'<td>'+res[i].expresswo+'</td>'
                    +'<td>'+res[i].expressname+'</td>'
                    +'<td>'+res[i].sendname+'</td>'
                    +'<td>'+res[i].sendphone+'</td>'
                    +'<td>'+res[i].sendaddress+'</td>'
                    +'<td>'+res[i].receivename+'</td>'
                    +'<td>'+res[i].receivephone+'</td>'
                    +'<td>'+res[i].receiveaddress+'</td>'
                    +'<td>'+res[i].way+'</td>'
                    +'</tr>';
				$("#request").append($(content));
			}
		},
		error:function(){
			layer.msg('连接失败')
		}
	})
}